package crack.lshape.yijian_mesh_mosler;

import java.io.IOException;

import math2.MathUtilities;
import crack.AbstractLshapeUsingSDAElementDemo;
import fem2.AbstractStructuralCrackDemo;
import fem2.Element;
import fem2.MaterialModel;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshPart;
import fem2.Model;
import fem2.element.crack_sda.SKONConstantJumpCSTElement;
import fem2.enu.State;
import fem2.material.StVenantKirchhoffMM;
import fem2.material.cohesive_law.CohesiveLaw;
import fem2.material.cohesive_law.Mode1JirasekExponentialCohesiveLaw;
import fem2.observer.StressObserver;
import fem2.observer.TimeStepObserver;
import fem2.pre_and_post.GidMeshGenerator;
import fem2.strategies.Strategy;

public class LshapeTriMeshYijianSKONConstantJumpCSTElementAndJirasekExponentialCohesiveLaw extends
		AbstractLshapeUsingSDAElementDemo {

	public LshapeTriMeshYijianSKONConstantJumpCSTElementAndJirasekExponentialCohesiveLaw() {
		meshFileName = "mesh1mosler-skon-jirasek.msh";
	}

	@Override
	public Mesh createMesh() {
		String fn = projectDir + '/' + projectName + '/' + meshFileName;
		MeshGenerator mg = new GidMeshGenerator(fn);
		Mesh mesh = mg.getMesh(2);
		return mesh;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		double E = 1e4;
		double nu = 0.2;
		double t = 200;
		State ss = State.PLANE_STRESS;
		MaterialModel mm = new StVenantKirchhoffMM(E, nu, t, 0, ss);
		return mm;
	}

	@Override
	public CohesiveLaw createCohesiveLaw(Model m) {
		double ft = 1;
		double Gf = 0.1e-1; // 0.1e-3
		double Dnn = 0.1;
		double Dmm = 0.1;
		return new Mode1JirasekExponentialCohesiveLaw(Gf, ft, Dnn, Dmm);
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm, CohesiveLaw cl) {
		Element e = new SKONConstantJumpCSTElement(mp, mm, cl);
		return e;
	}

	@Override
	public void addObservers(Model m, Strategy s, TimeStepObserver o) {
		super.addObservers(m, s, o);

		s.addObserver(new StressObserver(m));
	}

	public static void main(String[] args) throws IOException {

		AbstractStructuralCrackDemo sample = new LshapeTriMeshYijianSKONConstantJumpCSTElementAndJirasekExponentialCohesiveLaw();

		// double[] lambda = MathUtilities.createLambdaArray(7.15, 0.1, 7.8);
		// double[] lambda = MathUtilities.createLambdaArray(7.15, 0.1, 10);
		// double[] lambda = MathUtilities.createLambdaArray(7.15, 0.1, 15);
		double[] lambda = MathUtilities.createLambdaArray(7.15, 0.1, 30);

		sample.run(lambda);

	}
}
